package com.aaa.controller.sas;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.sas.TestPlanSas;
import com.aaa.service.sas.TestPlanSasServices;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ：马明钢
 * @date ：Created in 2022/8/30 19:17
 * @description：
 * @modified By：
 * @version:
 */
@Controller
@RequestMapping("/SASPlan")
public class TestPlanSasController extends BaseController {

    @Autowired
    TestPlanSasServices testPlanSasServices;

    @ResponseBody
    @RequestMapping("/queryAll.do")
    public Result queryAll(PageSortEntity pageSort, TestPlanSas ts){
        Page page = (Page) testPlanSasServices.queryAll(ts, pageSort);
        return success(page.getResult(),page.getTotal());
    }
    @LogMonitor
    @ResponseBody
    @RequestMapping("/insert.do")
    public Result insert( TestPlanSas ts){
        Integer l = testPlanSasServices.queryByTestCode();
        ts.setTestCode(l);
        boolean b = testPlanSasServices.insert(ts);
        if (b){
            return success();
        }
        return fail();
    }
    @LogMonitor
    @ResponseBody
    @RequestMapping("/delete.do")
    public Result delete(String id){
        boolean b = testPlanSasServices.delete(id);
        if (b){
            return success();
        }
        return fail();
    }
    @LogMonitor
    @ResponseBody
    @RequestMapping("/update.do")
    public Result update(TestPlanSas ts){
        boolean update = testPlanSasServices.update(ts);
        if (update){
            return success();
        }
        return fail();
    }

    @ResponseBody
    @RequestMapping("/repetitionName.do")
    public Result repetitionName(TestPlanSas ts){
        if (ObjectUtil.isEmpty(ts.getTestName())){
            return fail("不能为空");
        }
        boolean b = testPlanSasServices.repetitionName(ts);
        if (b){
            return success("题目名可用");
        }
        return  fail("题目重复不可用");
    }
}
